React = require('react')
{InteractionManager,View} = require('react-native')
Dimensions = require('Dimensions')
{width,height} = Dimensions.get('window')

moment = require('moment')


# 根据数据的过期时间，决定是否重新加载数据
lazyLoadData = (duration)->
  (WrappedComponent)->
    class newComponent extends React.Component
      constructor:->
        super()
      componentDidMount:->
        debugger
        if @props.connected
          if @props.lastFetchTime
            lastTime = moment(@props.lastFetchTime)
            currTime = moment(new Date())
            if currTime.subtract(duration).isAfter(lastTime)
              @props.fetchRefresh()
          else
            @props.fetchRefresh()
      render:->
        `<WrappedComponent {...this.props}/>`


module.exports = lazyLoadData
